﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using sauyou.Utils;

namespace sauyou.Admin
{
    public partial class dldj_List : ManagePage
    {
        public int pcount;                      //总条数
        public int page;                        //当前页
        public int pagesize;                    //设置每页显示的大小               

        protected void Page_Load(object sender, EventArgs e)
        {
            this.pagesize = webset.ArticlePageNum;

            if (!Page.IsPostBack)
            {
                chkLoginLevel("viewyhlx");
                //绑定类别

                RptBind();
            }
        }

        #region 数据列表绑定
        private void RptBind()
        {
            if (!int.TryParse(Request.Params["page"] as string, out this.page))
            {
                this.page = 0;
            }
            //获得总条数
            this.pcount = Convert.ToInt32(DbHelperSQL.GetSingle("select count(*) from user_dldj where 1=1 "));


            if (this.pcount > 0)
            {
                this.lbtnDel.Enabled = true;
            }
            else
            {
                this.lbtnDel.Enabled = false;
            }

            this.rptList.DataSource = GetPageList(this.pagesize, this.page, "user_dldj", "", " createtime desc ");
            this.rptList.DataBind();
        }
        #endregion
        
        //删除
        protected void lbtnDel_Click(object sender, EventArgs e)
        {
            chkLoginLevel("delyhlx");
           
            //批量删除
            for (int i = 0; i < rptList.Items.Count; i++)
            {
                int id = Convert.ToInt32(((HiddenField)rptList.Items[i].FindControl("hnID")).Value);
                CheckBox cb = (CheckBox)rptList.Items[i].FindControl("cb_id");
                HiddenField hnname = (HiddenField)rptList.Items[i].FindControl("hnname");
                
                if (cb.Checked)
                {
                    DbHelperSQL.ExecuteSql("delete from user_dldj where id in("+id+")");
                    //保存日志
                    SaveLogs("[代理等级]删除代理等级：" +hnname.Value);                    
                }
            }

            JscriptPrint("批量删除成功啦！", "dldj_List.aspx?page=0", "Success");
        }
    }
}
